interface jQuery{
    [index:number]:any
}
class jQuery {
    length:number
    constructor(selector:string) {
        let elements = Array.from(document.querySelectorAll(selector))
        let length = elements?elements.length :0
        this.length = length
        for (let i:number=0;i<length;i++){
            this[i] = elements[i]
        }
    }
    //如果传参就是赋值，没有传参就是取值
    html(htmlText:string){
        if (htmlText){
            for (let i:number=0;i<this.length;i++){
                this[i].innerHTML = htmlText
            }
        }else {
            return this[0].innerHTML
        }
    }
}
// interface global{
//     $:any
// }
interface Window{$:any}
window.$=function (selector:string){
    return new jQuery(selector)
}
// jQuery工厂就是函数返回类的实例